public class Test2 {
    public  ListNode swapPairs(ListNode head){
        ListNode dummyHead = new ListNode(0);
        dummyHead.next = head;
        ListNode prev = dummyHead;
        ListNode curr = head;
        /*要想反转相邻两个节点，要知道2后面的值，还要知道1前面的值
        * 所以将1前面的值用指针prev指向，当前要反转的第一个节点用curr来指向*/
        while (curr != null && curr.next != null){
            ListNode node1 = curr;
            ListNode node2 = curr.next;

            node1.next = node2.next;
            node2.next = node1;

            prev.next = node2;

            prev = node1;
            curr = node1.next;
        }
        return dummyHead.next;
    }
}
